package com.test.demo.javabasis.date;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAdjuster;

/**
 * 自定义实现下一个工作日
 */
public class NextWorkingDay implements TemporalAdjuster {
    @Override
    public Temporal adjustInto(Temporal temporal) {

        DayOfWeek day = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));
        int plusDay=1;
        if (day==DayOfWeek.FRIDAY)
            plusDay=3;
        else if (day==DayOfWeek.SATURDAY)
            plusDay=2;
        return temporal.plus(plusDay, ChronoUnit.DAYS);
    }

    public static void main(String[] args) {
        LocalDate localDate = LocalDate.of(2021, 1, 30);
        LocalDate localDate1 = localDate.with(new NextWorkingDay());
        System.out.println(localDate.toString()+localDate1.toString());
    }
}
